import { BTState } from "../BTState";
import { BTDecorator } from "./BTDecorator";

/**
 * [行为树]反转节点
 * 子节点返回succ时 -> 返回fail
 * 子节点返回fail时 -> 返回succ
 * 子节点返回run时 -> 返回run
 */
export class BTInverter<T = any> extends BTDecorator<T>{

    process(ctx: T): BTState {

        const state = this.child.tick(ctx);

        if (state === BTState.succ) {
            return BTState.fail;
        }

        if (state === BTState.fail) {
            return BTState.succ;
        }

        return BTState.run;
    }

}